function getPath() {
	$("#uploadpath-btn").click(function() {
		var datasend = {
			"uploadpath" : $("#uploadpath").val(),
			"relationpath" : $("#relationpath").val()
		}
		debugger;
		$.ajax({
			url : "../rest/config/uploadpath",
			type : "post",
			data : datasend,
			dataType : "text",
			success : function(data) {

			}
		});
	});
}

function addNewXpath() {
	$("#addNodeBtn").click(function() {
		if ($("#folderKey").val() != "" && $("#folderPath").val() != "") {
			var datasend = {
				"key" : $("#folderKey").val(),
				"value" : $("#folderPath").val()
			};
			var reg1 = new RegExp(/^[A-Za-z][a-zA-Z_0-9]*$/);
			var ssd = reg1.test($("#folderKey").val());
			debugger
			if (!ssd) {
				$("#msg").html("xPath name is not size up");
				return flase;
			}

			$.ajax({
				url : "../rest/config/addFolderNode",
				type : "post",
				data : datasend,
				dataType : "text",
				success : function(data) {
					$("#msg").html(data);
					viewXpath();
				},
				error : function(data) {
					$("#msg").html("connect error, status:" + data.status + " ,message:" + data.statusText);
				}
			});
		}

	});
}

function viewXpath() {
	$("#viewXpath").html("");
	$
			.ajax({
				url : "../rest/config/getNodeByXpath",
				type : "post",
				success : function(data) {
					$
							.each(
									data,
									function(k, v) {
										$("#viewXpath")
												.append(
														"<tr><td>"
																+ k
																+ "</td><td>"
																+ v
																+ "</td>"
																+ "<td><input type=\"button\" class=\"delete-xpath-file btn btn-default\" value=\"delete\"  data-deletexpath=\""
																+ k + "\"" + "></td>" + "</tr>");
									});
					deleteXpath();
				}
			});
}

function deleteXpath() {
	$(".delete-xpath-file").click(function() {

		var datasend = {
			"key" : $(this).attr("data-deletexpath")
		};
		$.ajax({
			url : "../rest/config/deleteFolderNode",
			type : "post",
			data : datasend,
			dataType : "text",
			success : function(data) {
				viewXpath();
			},
			error : function(data) {
				$("#msg").html("connect error, status:" + data.status + " ,message:" + data.statusText);
			}
		});
	});
}

$(function() {
	getPath();
	addNewXpath();
	viewXpath();

});